<template>
  <div class="shop-container">
    <div class="shop-list" v-for="item of shoplist" :key="item.id" @click="shopInfo(item.id)">
      <img :src="item.img_url" alt="此图已删除" />
      <h3>{{item.title}}</h3>
      <div class="shop-bottom">
        <p class="shop-price">
          <span class="new-price">￥{{item.sell_price}}</span>
          <span class="old-price">￥{{item.stock_quantity}}</span>
        </p>
        <p class="shop-hot">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="more">加载更多</mt-button>
  </div>
</template>

<script>
import Toast from 'mint-ui'
export default {
  name: "ShopList",
  data(){
      return{
          pageindex:1,//页码
          shoplist:[]
      }
  },
  created() {
      this.getshoplist();
  },
  methods:{
      // 下一页
      more(){
          this.pageindex++;
          this.getshoplist();
      },
      getshoplist(){
          this.$http.get('api/getgoods?pageindex='+this.pageindex).then(result =>{
            //   console.log('aa')
              let data=result.body;
              if(data.status===0){
                  //拼接数组
                  this.shoplist=this.shoplist.concat(data.message);
              }else{
                  Toast('获取数据失败');
              }
          })
      },
      // 跳转详情页
      shopInfo(id){
        // console.log(this);
        // this.$router.push('/home/shopinfo/'+id);
        // this.$router.push({path:'/home/shopinfo/'+id})
        // name是路由的名字
        this.$router.push({ name: 'shopinfo', params: {id:id}});
      }
  }
};
</script>

<style lang="scss" scoped>
.shop-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding:.14rem;
    margin-bottom: 1rem;
  .shop-list {
    border: .02rem solid #ccc;
    width: 49%;
    height: 5.86rem;
    box-shadow: 0 0 8px rgba(0,0,0,.3);
    margin: .06rem 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: .06rem;
    img {
      width: 100%;
    }
    h3 {
      font-size: 0.28rem;
      font-weight: 700;
    }
    .shop-bottom {
        width: 100%;
        background-color: #eee;
      .shop-price {
          line-height: .5rem;
          .new-price{
              color: #f00;
              font-size: .32rem;
              font-weight: bold;
              margin-right: .20rem;
          }
          .old-price{
              font-size: .24rem;
              text-decoration: line-through;
          }
      }
      .shop-hot {
          margin: 0;
          display: flex;
          justify-content: space-between;
          padding: 0 .1rem;
      }
    }
  }
}
</style>